package Demo;

import java.util.Random;

//宠物类
public class Pets extends User {
    private  String name; // 宠物名字
    private int health; // 血量
    private int attack; // 攻击力
    private  int defense; // 防御力

    //构造方法，getter and setter
    public Pets() {
    }

    public Pets(String name, int health, int attack, int defense) {
        this.name = name;
        this.health = health;
        this.attack = attack;
        this.defense = defense;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }

    public int getAttack() {
        return attack;
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public int getDefense() {
        return defense;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }
    String[] attackdesc={
            "%s对着%s使出了基础招式元素冲击波",
            "%s对着%s使出了基础招式宽恕",
            "%s对着%s使出了终极必杀技践踏之击",

    };
    String[] injuredesc={
            "结果%s躲过了攻击",
            "结果%s被命中了，处于眩晕状态5秒",
            "结果%s被命中了，你成功击败了它，可以选择将他捕获”",

    };


    //攻击方法的构造
    public void attack(Pets pets) {
        Random r = new Random();
        int index = r.nextInt(attackdesc.length);
        String Kunfu=attackdesc[index];
        System.out.printf(Kunfu,this.getName(),pets.getName());
        System.out.println();

        int hurt = r.nextInt(20) + 1;
        int remainblood = pets.getHealth() - hurt;

        remainblood = remainblood < 0 ? 0 : remainblood;
        pets.setHealth(remainblood);
        if(remainblood>90){
            System.out.printf(injuredesc[0],pets.getName());
        } else if(remainblood>0&&remainblood<=90) {
            System.out.printf(injuredesc[1],pets.getName());
        }else if(remainblood==0){
            System.out.printf(injuredesc[2],pets.getName());
        }
        System.out.println();
        System.out.println(this.getName() + "攻击了" + pets.getName() + "造成了" + hurt + "点的伤害" + pets.getName() + "" +
                "还剩下" + remainblood + "的血量");

    }

    public void showPetInfo() {
        System.out.println("宠物名字为；" + getName());
        System.out.println("血量为："+getHealth());

    }
}
